<?
// Function generate type url
function generate_type_url($module, $iCat, $nCat)
{
	global $con_mod_rewrite;
	$nCat = replace_rewrite_url($nCat, '-');
	
	$link = lang_path();
	switch ($module)
	{
		case 'news':
			$link .= $nCat . '-n' . $iCat . '.html';
			break;
		case 'product':
			$link .= $nCat . '-p' . $iCat . '.html';
			break;
		default:
			$link = lang_path() . 'type.php?module=' . $module . '&iCat=' . $iCat;
			break;
	}
	
	return $link;
}

// Function generate detail url
function generate_detail_url($module, $iCat, $iData, $nData)
{
	global $con_mod_rewrite;
	$nData = replace_rewrite_url($nData, '-');
	
	$link = lang_path();
	switch ($module)
	{
		case 'news':
			$link .= $nData . '-n' . $iCat . 'd' . $iData . '.html';
			break;
		case 'product':
			$link .= $nData . '-p' . $iCat . 'd' . $iData . '.html';
			break;
		case 'static':
			$link .= $nData . '-' . $iData . '.html';
			break;
		default:
			$link .= 'detail_' . $module . '.php?module=' . $module . '&iCat=' . $iCat . '&iData=' . $iData;
			break;
	}
	
	return $link;
}

// Function replace rewrite url
function replace_rewrite_url($string, $rc = '-', $removeAccent = 1, $lower = 1, $urlencode = 1)
{
	if ($lower)
	{
		$string = mb_strtolower($string, 'UTF-8');
	}
	if ($removeAccent)
	{
		$string	= removeAccent($string);
	}
	$string	= preg_replace('/[^A-Za-z0-9]+/', ' ', $string);
	$string	= str_replace('   ', ' ', trim($string));
	$string	= str_replace('  ', '', trim($string));
	$string	= str_replace(' ', $rc, $string);
	$string	= str_replace($rc . $rc, $rc, $string);
	$string	= str_replace($rc . $rc, $rc, $string);
	if ($urlencode == 1)
	{
		$string = urlencode($string);
	}
	return $string;
}
?>